<link href="css/bootstrap.css" rel="stylesheet" media="screen">
<style type="text/css">
    body{ background: url(""); }
</style>

 <div class="container" >
<?php

session_start();
include "lib/config.inc.php";
	
$username = post('username');
$password = post('password');
 ?>
<form method='post' action='login.php' class="col-md-offset-3 col-md-6 col-md-offset-3" style="margin-top: 15%;">
	<div class="panel panel-primary">
	<div class="panel-heading"><h5>SIGEAD - Sistema de Gestão Eclesiástica da Assembléia de Deus</h5></div>
		<div class="panel-body "><div class="col-md-offset-2 col-md-8 col-md-offset-2"><br>
			<fieldset >
				<div class="form-group">
					<div class="input-group">
		  				<span class="input-group-addon">Usuário</span>
				      	<input type="text" name="username" class="form-control" maxlength="15">
				    </div>
				</div>
			  	<div class="form-group">
			    	<div class="input-group">
		  				<span class="input-group-addon">Senha  :</span>
			      		<input type="password" name="password" class="form-control" maxlength="6">
			    	</div>
			  	</div>
			  	<div class="form-group">
		    		<div class="controls">
					<button type="submit" class="btn">Entrar</button>
					</div>
				</div>
			</fieldset>
		</div>
	</div>
	</div>
	</form>
	<?php 
	if ($username != null && $password != null) {
	
		// procurar no BD alguem que tenha o mesmo login e senha que foram enviados no BD....
		$password = sha1(md5($password));
		$res = mysql_query ("SELECT * FROM usuarios WHERE username = '$username' AND password = '$password'");
		$usuario = mysql_fetch_array($res);
		
		if (!$usuario){
			echo '<div class="panel"> <div class="panel-body"><div class="alert col-md-offset-3 col-md-6 col-md-offset-3 alert-danger">
				<button type="button" class="close" data-dismiss="alert"></button>
				<center> <strong>ERRO!</strong> Login ou senha inválidos!</center>
				</div></div></div>';
		}
		else {
			$_SESSION['usuario'] = $usuario;
			header('Location:index.php');
			die ();
		}
		
	}else{
		echo '<div class="panel"> <div class="panel-body"><div class="alert col-md-offset-3 col-md-6 col-md-offset-3 alert-warning">
				<button type="button" class="close" data-dismiss="alert"></button>
				<center> <strong>ATENÇÃO!</strong> Preencha os campos de login e senha para acessar o sistema.</center>
				</div></div></div>';
	}
	?>
</div>